package com.example.guideapp.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;

import com.example.guideapp.R;
import com.example.guideapp.adapter.MyFragmentPagerAdapter;

public class MainActivity extends AppCompatActivity {

    private TabLayout mTablayout;
    private ViewPager mViewPager;

    private MyFragmentPagerAdapter myFragmentPagerAdapter;

    private TabLayout.Tab tabOne;
    private TabLayout.Tab tabTwo;
    private TabLayout.Tab tabThree;

    private Toolbar toolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //隐藏掉整个ActionBar
        //getSupportActionBar().hide();

        setContentView(R.layout.activity_main);

        initViews();

        initToolBar();
    }

    private void initToolBar() {
        toolbar = (Toolbar) findViewById(R.id.toolBar);

        toolbar.setLogo(R.mipmap.ic_launcher1);
        toolbar.setTitle("节日祝福短信大全");
        toolbar.setSubtitle("节日问候、日历");


        toolbar.inflateMenu(R.menu.menu_main);

        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {

                Intent i = new Intent();

                int menuId = item.getItemId();
                switch (menuId){
                    case R.id.action_calendar :
                        i.setClass(MainActivity.this,CalendarDateActivity.class);
                        break;
                    case R.id.action_history_day :
                        i.setClass(MainActivity.this,HistoryDayActivity.class);
                        break;
                    case R.id.action_about :
                        i.setClass(MainActivity.this,AboutActivity.class);

                        break;
                    default:
                }
                if (i == null){
                    return false;
                }
                startActivity(i);
                return  true;
            }
        });
    }

    private void initViews() {
        mTablayout = (TabLayout) findViewById(R.id.tabLayout_main);
        mViewPager = (ViewPager) findViewById(R.id.viewPager_main);

        //将适配器和ViewPager绑定在一起
        myFragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager());
        mViewPager.setAdapter(myFragmentPagerAdapter);

        //将Tbalayout和ViewPager绑定在一起
        mTablayout.setupWithViewPager(mViewPager);

        //指定Tab的位置
        tabOne = mTablayout.getTabAt(0);
        tabTwo = mTablayout.getTabAt(1);
        tabThree = mTablayout.getTabAt(2);

        //设置Tab的图标
//        tabOne.setIcon(R.mipmap.ic_launcher);
//        tabTwo.setIcon(R.mipmap.ic_launcher);
//        tabThree.setIcon(R.mipmap.ic_launcher);
    }
}
